{include file="public/header" /}
<div class="pd-20">
    <form action="" method="post" class="form form-horizontal" id="form-add">
        <div class="row cl">
            <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>昵称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$data.nickname|default=''}" name="data[nickname]" datatype="*" placeholder="请输入管理员昵称"  nullmsg="请输入管理员昵称">
            </div>
            <div class="col-4"> </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>账号：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$data.username|default=''}" placeholder="请输入管理员账号" name="data[username]" datatype="*" nullmsg="请输入管理员账号" {if isset($data.is_default) && $data.is_default == 1}disabled{/if} >
            </div>
            <div class="col-4" id="error"> </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" value="" name="data[password]" placeholder="请输入密码" datatype="*" nullmsg="请输入密码">
                <span style="color:red">*{if isset($data.id) && $data.id > 0}密码若不填写不修改密码{else}密码若不填写默认为:123456{/if}</span>
            </div>
            <div class="col-4"> </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>权限：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                {foreach :config('menu.menu') as $k => $v}
                   {if $v.show == true}
                    <div style="margin-top: 10px;font-weight: bold;">{$v.name}</div>
                        {foreach $v.sub as $x => $y}
                        <div class="radio-box">
                            <input type="checkbox" id="role-{$k}-{$x}" value="{$y.uri}" name="data[role][]" {if isset($data.role) && in_array($y.uri, $data.role)} checked {/if}>
                            <label for="role-{$k}-{$x}">{$y.name}</label>
                        </div>
                        {/foreach}
                    {/if}
                {/foreach}
            </div>
            <div class="col-4"> </div>
        </div>

        <div class="row cl">
            <div class="col-9 col-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</div>
{include file="public/footer" /}
<script type="text/javascript">
    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-add").validate({
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    success:function(data){
                        console.log(data);
                        if(data.status == 0){
                            layer.msg("操作成功",{icon:1,time:1000,shade: [0.3, '#000']},function(){
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:1000,shade: [0.3, '#000']});
                        }
                    },
                    error:function(error){
                        layer.msg('系统发生了错误',{icon:2,time:3000,shade: [0.5, '#FF0000']});
                    }
                });

            }
        });
    });
</script>